package Test_1009;

import org.w3c.dom.ls.LSOutput;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-10-09
 * Time: 22:03
 */

public class Test_1009 {
    //处理异常
    //throws处理
    public static void fun1(int a)throws ArithmeticException{
          if(a==1){
              throw new ArithmeticException();
          }
    }

    public static void main7(String[] args){
        //不会同时抛出多个异常
        try{
          fun1(2);
        }catch(ArithmeticException e){
            System.out.println("捕获");
            //打印错误信息
            e.printStackTrace();
        }finally {
            //finally资源的释放
            System.out.println("zx");
        }
        System.out.println("zc");
    }
    //throw:抛出异常
    public static void test(int a){
        if(a==1){
            throw new ArithmeticException("a==1");
        }
    }

    public static void main6(String[] args){
           test(1);
    }
    //异常不等于语法错误
    //发生在异常之前可以执行，异常之后无法执行
    //
    //1.算术异常
    public static void main1(String[] args) {
        System.out.println(10/0);
    }
    //2.数组下标越界异常
    public static void main2(String[] args) {
        int[] a={1,2,3,4};
        System.out.println(a[5]);
    }
    //3.空指针异常
    public static void main3(String[] args) {
        int[] a=null;
        System.out.println(a.length);
        System.out.println(a[0]);
    }

    //4.类型转换异常
    //trhows:声明可能出现的异常，后面可以抛出很多个异常
    public static void main(String[] args) throws CloneNotSupportedException {
        Cat cat=new Cat();
        Cat cat1=(Cat)cat.clone();
    }
    public static void fun(){
        fun();
    }

}
class Cat implements Cloneable{
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}